package com.saclub.app.handler;

import com.offroader.utils.StringUtils;
import com.offroader.utils.ViewUtils;
import com.saclub.app.R;
import com.saclub.app.bean.page.AccountUserPage;
import com.saclub.app.bean.part.User;
import com.saclub.app.common.AccessTokenKeeper;
import com.saclub.app.fragment.AccountEditFragment;

public class UpdateResponseHandler extends MyBaseHttpResponseHandler<AccountEditFragment, AccountUserPage> {

	@Override
	public void deal() {

		User user = page.getUser();
		if (user != null && StringUtils.isNotBlank(user.getName())) {

			AccessTokenKeeper tokenKeeper = AccessTokenKeeper.readAccessToken(caller.getActivity());

			if (tokenKeeper.isLogin()) {//如果 已登陆更新本地用户信息
				
				user.setUid(tokenKeeper.getUser().getUid());
				
				String mAccessToken = user.getUid();
				String mExpiresTime = String.valueOf(Integer.MAX_VALUE);
				String openId = user.getUid();
				
				tokenKeeper = new AccessTokenKeeper(mAccessToken, mExpiresTime, openId, user);
				AccessTokenKeeper.keepAccessToken(caller.getActivity(), tokenKeeper);
				
			}
			
			ViewUtils.toast(R.string.tip_update_success);

			caller.getActivity().finish();

		} else {
			ViewUtils.toast(R.string.tip_update_fails);
		}

	}

}

